//
//  string_demo.cpp
//  cpp_learn
//
//  Created by 李贺 on 2021/12/14.
//

#include "string_demo.hpp"


namespace string_demo_002 {

void test_Iterators() {
    string sss = "sksksk";

    for (string::iterator it = sss.begin(); it != sss.end(); it++) {
        cout << *it << endl;
    }
    
    std::string str ("now step live...");
    for (std::string::reverse_iterator rit=str.rbegin(); rit!=str.rend(); ++rit) {
        std::cout << *rit << endl;
    }
        
}

int string_shrink ()
{
  std::string str (100,'x');
  std::cout << "1. capacity of str: " << str.capacity() << '\n';

  str.resize(10);
  std::cout << "2. capacity of str: " << str.capacity() << '\n';

  str.shrink_to_fit();
  std::cout << "3. capacity of str: " << str.capacity() << '\n';

  return 0;
}

void string_constructure() {
    string s0;
    string s1(s0);
    string s2 = s1;
    string s3 = "888888888888";
    string s4(s3,2,3);
    string s5("k",17);
    string s6("adkdk");
    string s7(77, 'u');
    string s8 (s0.begin(), s0.begin()+7);
}

void string_access() {
    string s1("akdkdkdkkd");
    cout << s1[3] << endl;
    cout << s1.at(0) << endl;
    cout << s1.back() << endl;
    cout << s1.front() << endl;
}

void string_modify() {
    string s0("a");
    string s1("b");
    s0 += s1;
    cout << s0 << endl;
    
    s0.append("kkk");
    s0.push_back('b');
    cout << s0 << endl;
    string s3 = "mmmm";
    s0.assign(s3);
    cout << s0 << endl;
    
    s0.insert(2, "bbb");
    cout << s0 << endl;
    
    s0.erase(s0.begin() + 3);
    cout << s0 << endl;
    
    s0.replace(0, 4, "jj");
    cout << s0 << endl;
    s0.replace(0, 1, "uuuuuu", 2);
    cout << s0 << endl;
    
    s0.swap(s3);
    cout << s0 << endl;
    
    string s4("aabbccddd");
    cout << s4.find("bb") << endl;
}

void string_size() {
    string sss = "kkkkk";
    cout << sss.size() << endl;
    cout << sss.length() << endl;
    cout << sss.max_size() << endl;
    sss.resize(99, 'l');
    cout << sss << endl;
    cout << sss.capacity() << endl;
    sss.reserve(120);
    cout << sss.capacity() << endl;
    cout << sss << endl;
    sss.clear();
    cout << sss << endl;
    cout << sss.empty() << endl;
}

void test_size() {
    string_modify();
}






}
